﻿Imports KumaSystem.Activities.FileSystem
Imports NUnit.Framework
Imports Microsoft.Activities.UnitTesting

<TestFixture()>
Public Class TestFolderCopy

    <SetUp()>
    Public Sub Setup()
        If Not IO.Directory.Exists("D:\ActivityTest") Then IO.Directory.CreateDirectory("D:\ActivityTest")
        For Each childFile In IO.Directory.GetFiles("D:\ActivityTest")
            My.Computer.FileSystem.DeleteFile(childFile)
        Next
        If Not IO.Directory.Exists("D:\ActivityTest\TestDestination") Then IO.Directory.CreateDirectory("D:\ActivityTest\TestDestination")
        For Each childFile In IO.Directory.GetFiles("D:\ActivityTest\TestDestination")
            My.Computer.FileSystem.DeleteFile(childFile)
        Next
        If Not IO.Directory.Exists("D:\ActivityTest\TestDestination2") Then IO.Directory.CreateDirectory("D:\ActivityTest\TestDestination2")
        For Each childFile In IO.Directory.GetFiles("D:\ActivityTest\TestDestination2")
            My.Computer.FileSystem.DeleteFile(childFile)
        Next
        If Not IO.File.Exists("D:\ActivityTest\Test1.txt") Then
            My.Computer.FileSystem.WriteAllText("D:\ActivityTest\Test1.txt", "This is test strings", False)
            My.Computer.FileSystem.WriteAllText("D:\ActivityTest\TestDestination\Test1.txt", "This is test strings", False)
            My.Computer.FileSystem.WriteAllText("D:\ActivityTest\TestDestination2\Test1.txt", "This is test", False)
        End If
        If Not IO.File.Exists("D:\ActivityTest\Test2.txt") Then
            My.Computer.FileSystem.WriteAllText("D:\ActivityTest\Test2.txt", "This is test strings2", False)
        End If
    End Sub

    <TearDown()>
    Public Sub TearDown()
        Try
            For Each childFile In IO.Directory.GetFiles("D:\ActivityTest\TestDestination2")
                My.Computer.FileSystem.DeleteFile(childFile)
            Next
            For Each childFile In IO.Directory.GetFiles("D:\ActivityTest\TestDestination")
                My.Computer.FileSystem.DeleteFile(childFile)
            Next
            For Each childFile In IO.Directory.GetFiles("D:\ActivityTest")
                My.Computer.FileSystem.DeleteFile(childFile)
            Next
            My.Computer.FileSystem.DeleteDirectory("D:\ActivityTest\TestDestination2", FileIO.DeleteDirectoryOption.DeleteAllContents)
            My.Computer.FileSystem.DeleteDirectory("D:\ActivityTest\TestDestination", FileIO.DeleteDirectoryOption.DeleteAllContents)
            My.Computer.FileSystem.DeleteDirectory("D:\ActivityTest", FileIO.DeleteDirectoryOption.DeleteAllContents)
        Catch ex As Exception

        End Try
    End Sub

    <TestCase("D:\ActivityTest\TestDestination", "D:\ActivityTest\TestDestination2", True, "This is test strings", True)>
    <TestCase("D:\ActivityTest\TestDestination", "D:\ActivityTest\TestDestination2", False, "This is test", False)>
    <TestCase("D:\ActivityTest\TestDestination", "D:\ActivityTest\TestDestination3", True, "This is test strings", True)>
    <TestCase("D:\ActivityTest\TestDestination", "D:\ActivityTest\TestDestination3", False, "This is test strings", True)>
    Public Sub CopyTestNormal(ByVal source As String, ByVal destination As String, ByVal over As Boolean, ByVal resultStrings As String, ByVal execResult As Boolean)

        Dim testActivity As New FolderCopyActivity With {
            .OriginalFolder = source, .TargetFolder = destination, .OverrideFile = over}
        Dim wfInvoker As New WorkflowInvokerTest(testActivity)
        wfInvoker.TestActivity()

        Dim srcPath = IO.Path.Combine(source, "Test1.txt")
        Dim destPath = IO.Path.Combine(destination, "Test1.txt")
        Console.WriteLine("Src : " + srcPath)
        Console.WriteLine("Dst : " + destPath)

        Assert.True(IO.File.Exists(srcPath))
        Assert.True(IO.File.Exists(destPath))

        Dim outResult = My.Computer.FileSystem.ReadAllText(destPath)
        Console.WriteLine("Output : " + outResult)

        If execResult Then Assert.True(outResult = resultStrings)
        wfInvoker.AssertOutArgument.AreEqual("Result", execResult)

    End Sub

End Class
